
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 06/12/2011 20:25:33
-- Generated from EDMX file: D:\Development\ClubManagement\EislaufScb\EislaufScb.Model\ClubModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [ClubManagement];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_AddressCity]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_City] DROP CONSTRAINT [FK_AddressCity];
GO
IF OBJECT_ID(N'[dbo].[FK_AddressStreet]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_Street] DROP CONSTRAINT [FK_AddressStreet];
GO
IF OBJECT_ID(N'[dbo].[FK_AddressCountry]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_Country] DROP CONSTRAINT [FK_AddressCountry];
GO
IF OBJECT_ID(N'[dbo].[FK_ClubAddress]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_Address] DROP CONSTRAINT [FK_ClubAddress];
GO
IF OBJECT_ID(N'[dbo].[FK_PersonAddress]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_Address] DROP CONSTRAINT [FK_PersonAddress];
GO
IF OBJECT_ID(N'[dbo].[FK_PersonTest]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_Certification] DROP CONSTRAINT [FK_PersonTest];
GO
IF OBJECT_ID(N'[dbo].[FK_AddressTest]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_Certification] DROP CONSTRAINT [FK_AddressTest];
GO
IF OBJECT_ID(N'[dbo].[FK_ClubBlog]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_Blog] DROP CONSTRAINT [FK_ClubBlog];
GO
IF OBJECT_ID(N'[dbo].[FK_BlogBlogEntry]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_BlogEntry] DROP CONSTRAINT [FK_BlogBlogEntry];
GO
IF OBJECT_ID(N'[dbo].[FK_GalleryImage]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_Image] DROP CONSTRAINT [FK_GalleryImage];
GO
IF OBJECT_ID(N'[dbo].[FK_PersonPhone]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_Phone] DROP CONSTRAINT [FK_PersonPhone];
GO
IF OBJECT_ID(N'[dbo].[FK_ClubInfrastructureObject]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_InfrastructureObject] DROP CONSTRAINT [FK_ClubInfrastructureObject];
GO
IF OBJECT_ID(N'[dbo].[FK_AddressInfrastructureObject]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_InfrastructureObject] DROP CONSTRAINT [FK_AddressInfrastructureObject];
GO
IF OBJECT_ID(N'[dbo].[FK_PersonHobby]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_Hobby] DROP CONSTRAINT [FK_PersonHobby];
GO
IF OBJECT_ID(N'[dbo].[FK_PersonAdditionalTrainerData]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_AdditionalTrainerData] DROP CONSTRAINT [FK_PersonAdditionalTrainerData];
GO
IF OBJECT_ID(N'[dbo].[FK_ClubCourse]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_Course] DROP CONSTRAINT [FK_ClubCourse];
GO
IF OBJECT_ID(N'[dbo].[FK_CoursePerson]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_Person] DROP CONSTRAINT [FK_CoursePerson];
GO
IF OBJECT_ID(N'[dbo].[FK_PersonCurriculumViateEntry]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_CurriculumViateEntry] DROP CONSTRAINT [FK_PersonCurriculumViateEntry];
GO
IF OBJECT_ID(N'[dbo].[FK_PersonPersonRoleRelation]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_PersonRoleRelation] DROP CONSTRAINT [FK_PersonPersonRoleRelation];
GO
IF OBJECT_ID(N'[dbo].[FK_PersonPersonImage]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_PersonImage] DROP CONSTRAINT [FK_PersonPersonImage];
GO
IF OBJECT_ID(N'[dbo].[FK_PersonProfession]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_Profession] DROP CONSTRAINT [FK_PersonProfession];
GO
IF OBJECT_ID(N'[dbo].[FK_BlogEntryBlogEntryComment]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_BlogEntryComment] DROP CONSTRAINT [FK_BlogEntryBlogEntryComment];
GO
IF OBJECT_ID(N'[dbo].[FK_PersonTypePersonRoleRelation]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_PersonRoleRelation] DROP CONSTRAINT [FK_PersonTypePersonRoleRelation];
GO
IF OBJECT_ID(N'[dbo].[FK_PhonePhoneType]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_PhoneType] DROP CONSTRAINT [FK_PhonePhoneType];
GO
IF OBJECT_ID(N'[dbo].[FK_Address_inherits_BaseEntity]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_Address] DROP CONSTRAINT [FK_Address_inherits_BaseEntity];
GO
IF OBJECT_ID(N'[dbo].[FK_City_inherits_BaseEntity]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_City] DROP CONSTRAINT [FK_City_inherits_BaseEntity];
GO
IF OBJECT_ID(N'[dbo].[FK_Street_inherits_BaseEntity]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_Street] DROP CONSTRAINT [FK_Street_inherits_BaseEntity];
GO
IF OBJECT_ID(N'[dbo].[FK_Country_inherits_BaseEntity]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_Country] DROP CONSTRAINT [FK_Country_inherits_BaseEntity];
GO
IF OBJECT_ID(N'[dbo].[FK_Club_inherits_BaseEntity]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_Club] DROP CONSTRAINT [FK_Club_inherits_BaseEntity];
GO
IF OBJECT_ID(N'[dbo].[FK_Person_inherits_BaseEntity]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_Person] DROP CONSTRAINT [FK_Person_inherits_BaseEntity];
GO
IF OBJECT_ID(N'[dbo].[FK_Certification_inherits_BaseEntity]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_Certification] DROP CONSTRAINT [FK_Certification_inherits_BaseEntity];
GO
IF OBJECT_ID(N'[dbo].[FK_Blog_inherits_BaseEntity]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_Blog] DROP CONSTRAINT [FK_Blog_inherits_BaseEntity];
GO
IF OBJECT_ID(N'[dbo].[FK_BlogEntry_inherits_BaseEntity]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_BlogEntry] DROP CONSTRAINT [FK_BlogEntry_inherits_BaseEntity];
GO
IF OBJECT_ID(N'[dbo].[FK_Gallery_inherits_BaseEntity]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_Gallery] DROP CONSTRAINT [FK_Gallery_inherits_BaseEntity];
GO
IF OBJECT_ID(N'[dbo].[FK_Image_inherits_BaseEntity]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_Image] DROP CONSTRAINT [FK_Image_inherits_BaseEntity];
GO
IF OBJECT_ID(N'[dbo].[FK_Phone_inherits_BaseEntity]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_Phone] DROP CONSTRAINT [FK_Phone_inherits_BaseEntity];
GO
IF OBJECT_ID(N'[dbo].[FK_InfrastructureObject_inherits_BaseEntity]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_InfrastructureObject] DROP CONSTRAINT [FK_InfrastructureObject_inherits_BaseEntity];
GO
IF OBJECT_ID(N'[dbo].[FK_Hobby_inherits_BaseEntity]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_Hobby] DROP CONSTRAINT [FK_Hobby_inherits_BaseEntity];
GO
IF OBJECT_ID(N'[dbo].[FK_AdditionalTrainerData_inherits_BaseEntity]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_AdditionalTrainerData] DROP CONSTRAINT [FK_AdditionalTrainerData_inherits_BaseEntity];
GO
IF OBJECT_ID(N'[dbo].[FK_Course_inherits_BaseEntity]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_Course] DROP CONSTRAINT [FK_Course_inherits_BaseEntity];
GO
IF OBJECT_ID(N'[dbo].[FK_CurriculumViateEntry_inherits_BaseEntity]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_CurriculumViateEntry] DROP CONSTRAINT [FK_CurriculumViateEntry_inherits_BaseEntity];
GO
IF OBJECT_ID(N'[dbo].[FK_PersonRoleRelation_inherits_BaseEntity]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_PersonRoleRelation] DROP CONSTRAINT [FK_PersonRoleRelation_inherits_BaseEntity];
GO
IF OBJECT_ID(N'[dbo].[FK_PersonImage_inherits_BaseEntity]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_PersonImage] DROP CONSTRAINT [FK_PersonImage_inherits_BaseEntity];
GO
IF OBJECT_ID(N'[dbo].[FK_Profession_inherits_BaseEntity]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_Profession] DROP CONSTRAINT [FK_Profession_inherits_BaseEntity];
GO
IF OBJECT_ID(N'[dbo].[FK_BlogEntryComment_inherits_BaseEntity]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_BlogEntryComment] DROP CONSTRAINT [FK_BlogEntryComment_inherits_BaseEntity];
GO
IF OBJECT_ID(N'[dbo].[FK_PersonType_inherits_BaseEntity]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_PersonType] DROP CONSTRAINT [FK_PersonType_inherits_BaseEntity];
GO
IF OBJECT_ID(N'[dbo].[FK_PhoneType_inherits_BaseEntity]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_PhoneType] DROP CONSTRAINT [FK_PhoneType_inherits_BaseEntity];
GO
IF OBJECT_ID(N'[dbo].[FK_ClubType_inherits_BaseEntity]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_ClubType] DROP CONSTRAINT [FK_ClubType_inherits_BaseEntity];
GO
IF OBJECT_ID(N'[dbo].[FK_CategoryType_inherits_BaseEntity]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_CategoryType] DROP CONSTRAINT [FK_CategoryType_inherits_BaseEntity];
GO
IF OBJECT_ID(N'[dbo].[FK_CourseType_inherits_BaseEntity]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_CourseType] DROP CONSTRAINT [FK_CourseType_inherits_BaseEntity];
GO
IF OBJECT_ID(N'[dbo].[FK_InfrastructureType_inherits_BaseEntity]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_InfrastructureType] DROP CONSTRAINT [FK_InfrastructureType_inherits_BaseEntity];
GO
IF OBJECT_ID(N'[dbo].[FK_MemberType_inherits_BaseEntity]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BaseEntitySet_MemberType] DROP CONSTRAINT [FK_MemberType_inherits_BaseEntity];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[BaseEntitySet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseEntitySet];
GO
IF OBJECT_ID(N'[dbo].[BaseEntitySet_Address]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseEntitySet_Address];
GO
IF OBJECT_ID(N'[dbo].[BaseEntitySet_City]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseEntitySet_City];
GO
IF OBJECT_ID(N'[dbo].[BaseEntitySet_Street]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseEntitySet_Street];
GO
IF OBJECT_ID(N'[dbo].[BaseEntitySet_Country]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseEntitySet_Country];
GO
IF OBJECT_ID(N'[dbo].[BaseEntitySet_Club]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseEntitySet_Club];
GO
IF OBJECT_ID(N'[dbo].[BaseEntitySet_Person]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseEntitySet_Person];
GO
IF OBJECT_ID(N'[dbo].[BaseEntitySet_Certification]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseEntitySet_Certification];
GO
IF OBJECT_ID(N'[dbo].[BaseEntitySet_Blog]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseEntitySet_Blog];
GO
IF OBJECT_ID(N'[dbo].[BaseEntitySet_BlogEntry]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseEntitySet_BlogEntry];
GO
IF OBJECT_ID(N'[dbo].[BaseEntitySet_Gallery]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseEntitySet_Gallery];
GO
IF OBJECT_ID(N'[dbo].[BaseEntitySet_Image]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseEntitySet_Image];
GO
IF OBJECT_ID(N'[dbo].[BaseEntitySet_Phone]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseEntitySet_Phone];
GO
IF OBJECT_ID(N'[dbo].[BaseEntitySet_InfrastructureObject]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseEntitySet_InfrastructureObject];
GO
IF OBJECT_ID(N'[dbo].[BaseEntitySet_Hobby]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseEntitySet_Hobby];
GO
IF OBJECT_ID(N'[dbo].[BaseEntitySet_AdditionalTrainerData]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseEntitySet_AdditionalTrainerData];
GO
IF OBJECT_ID(N'[dbo].[BaseEntitySet_Course]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseEntitySet_Course];
GO
IF OBJECT_ID(N'[dbo].[BaseEntitySet_CurriculumViateEntry]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseEntitySet_CurriculumViateEntry];
GO
IF OBJECT_ID(N'[dbo].[BaseEntitySet_PersonRoleRelation]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseEntitySet_PersonRoleRelation];
GO
IF OBJECT_ID(N'[dbo].[BaseEntitySet_PersonImage]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseEntitySet_PersonImage];
GO
IF OBJECT_ID(N'[dbo].[BaseEntitySet_Profession]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseEntitySet_Profession];
GO
IF OBJECT_ID(N'[dbo].[BaseEntitySet_BlogEntryComment]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseEntitySet_BlogEntryComment];
GO
IF OBJECT_ID(N'[dbo].[BaseEntitySet_PersonType]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseEntitySet_PersonType];
GO
IF OBJECT_ID(N'[dbo].[BaseEntitySet_PhoneType]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseEntitySet_PhoneType];
GO
IF OBJECT_ID(N'[dbo].[BaseEntitySet_ClubType]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseEntitySet_ClubType];
GO
IF OBJECT_ID(N'[dbo].[BaseEntitySet_CategoryType]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseEntitySet_CategoryType];
GO
IF OBJECT_ID(N'[dbo].[BaseEntitySet_CourseType]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseEntitySet_CourseType];
GO
IF OBJECT_ID(N'[dbo].[BaseEntitySet_InfrastructureType]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseEntitySet_InfrastructureType];
GO
IF OBJECT_ID(N'[dbo].[BaseEntitySet_MemberType]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BaseEntitySet_MemberType];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'BaseEntitySet'
CREATE TABLE [dbo].[BaseEntitySet] (
    [Id] bigint IDENTITY(1,1) NOT NULL,
    [Version] DateTime2  NOT NULL,
    [Creator] nvarchar(max)  NOT NULL,
    [CreateDate] DateTime2  NOT NULL
);
GO

-- Creating table 'BaseEntitySet_Address'
CREATE TABLE [dbo].[BaseEntitySet_Address] (
    [Id] bigint  NOT NULL,
    [Club_Id] bigint  NULL,
    [Person_Id] bigint  NULL
);
GO

-- Creating table 'BaseEntitySet_City'
CREATE TABLE [dbo].[BaseEntitySet_City] (
    [Name] nvarchar(max)  NOT NULL,
    [Postalcode] int  NOT NULL,
    [Id] bigint  NOT NULL,
    [Address_Id] bigint  NULL
);
GO

-- Creating table 'BaseEntitySet_Street'
CREATE TABLE [dbo].[BaseEntitySet_Street] (
    [Name] nvarchar(max)  NOT NULL,
    [Extension] nvarchar(max)  NULL,
    [Number] int  NOT NULL,
    [Id] bigint  NOT NULL,
    [Address_Id] bigint  NULL
);
GO

-- Creating table 'BaseEntitySet_Country'
CREATE TABLE [dbo].[BaseEntitySet_Country] (
    [Name] nvarchar(max)  NOT NULL,
    [ISOName] nvarchar(max)  NOT NULL,
    [Id] bigint  NOT NULL,
    [Address_Id] bigint  NULL
);
GO

-- Creating table 'BaseEntitySet_Club'
CREATE TABLE [dbo].[BaseEntitySet_Club] (
    [Name] nvarchar(max)  NOT NULL,
    [FoundingYear] DateTime2  NOT NULL,
    [History] nvarchar(max)  NOT NULL,
    [Type] nvarchar(max)  NOT NULL,
    [Url] nvarchar(max)  NOT NULL,
    [Id] bigint  NOT NULL
);
GO

-- Creating table 'BaseEntitySet_Person'
CREATE TABLE [dbo].[BaseEntitySet_Person] (
    [EMail] nvarchar(max)  NULL,
    [FirstName] nvarchar(max)  NOT NULL,
    [LastName] nvarchar(max)  NOT NULL,
    [MiddleName] nvarchar(max)  NULL,
    [AreaOfResponsibility] nvarchar(max)  NULL,
    [TrainedBy] nvarchar(max)  NULL,
    [DateOfBirth] DateTime2  NULL,
    [Id] bigint  NOT NULL,
    [Course_Id] bigint  NULL
);
GO

-- Creating table 'BaseEntitySet_Certification'
CREATE TABLE [dbo].[BaseEntitySet_Certification] (
    [AccomplishDate] DateTime2  NOT NULL,
    [Rating] int  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [Id] bigint  NOT NULL,
    [Person_Id] bigint  NULL,
    [Address_Id] bigint  NULL
);
GO

-- Creating table 'BaseEntitySet_Blog'
CREATE TABLE [dbo].[BaseEntitySet_Blog] (
    [Name] nvarchar(max)  NOT NULL,
    [Id] bigint  NOT NULL,
    [Club_Id] bigint  NOT NULL
);
GO

-- Creating table 'BaseEntitySet_BlogEntry'
CREATE TABLE [dbo].[BaseEntitySet_BlogEntry] (
    [Content] nvarchar(max)  NOT NULL,
    [PublishingDate] DateTime2  NOT NULL,
    [Title] nvarchar(max)  NOT NULL,
    [Id] bigint  NOT NULL,
    [Blog_Id] bigint  NULL
);
GO

-- Creating table 'BaseEntitySet_Gallery'
CREATE TABLE [dbo].[BaseEntitySet_Gallery] (
    [Name] nvarchar(max)  NOT NULL,
    [Id] bigint  NOT NULL
);
GO

-- Creating table 'BaseEntitySet_Image'
CREATE TABLE [dbo].[BaseEntitySet_Image] (
    [Name] nvarchar(max)  NOT NULL,
    [ImageDate] varbinary(max)  NOT NULL,
    [Id] bigint  NOT NULL,
    [Gallery_Id] bigint  NULL
);
GO

-- Creating table 'BaseEntitySet_Phone'
CREATE TABLE [dbo].[BaseEntitySet_Phone] (
    [SubScriberNumber] nvarchar(max)  NOT NULL,
    [Id] bigint  NOT NULL,
    [Person_Id] bigint  NULL
);
GO

-- Creating table 'BaseEntitySet_InfrastructureObject'
CREATE TABLE [dbo].[BaseEntitySet_InfrastructureObject] (
    [GeoData] nvarchar(max)  NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Image] varbinary(max)  NOT NULL,
    [OpeningStatus] bit  NOT NULL,
    [Id] bigint  NOT NULL,
    [Club_Id] bigint  NOT NULL,
    [Address_Id] bigint  NULL
);
GO

-- Creating table 'BaseEntitySet_Hobby'
CREATE TABLE [dbo].[BaseEntitySet_Hobby] (
    [Name] nvarchar(max)  NOT NULL,
    [Id] bigint  NOT NULL,
    [Person_Id] bigint  NULL
);
GO

-- Creating table 'BaseEntitySet_AdditionalTrainerData'
CREATE TABLE [dbo].[BaseEntitySet_AdditionalTrainerData] (
    [IsTrainerSince] nvarchar(max)  NOT NULL,
    [IsTrainerAt] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [Id] bigint  NOT NULL,
    [Person_Id] bigint  NULL
);
GO

-- Creating table 'BaseEntitySet_Course'
CREATE TABLE [dbo].[BaseEntitySet_Course] (
    [Start] DateTime2  NOT NULL,
    [End] DateTime2  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [CourseType] nvarchar(max)  NOT NULL,
    [Id] bigint  NOT NULL,
    [Club_Id] bigint  NULL
);
GO

-- Creating table 'BaseEntitySet_CurriculumViateEntry'
CREATE TABLE [dbo].[BaseEntitySet_CurriculumViateEntry] (
    [From] DateTime2  NULL,
    [End] DateTime2  NULL,
    [Description] nvarchar(max)  NOT NULL,
    [Title] nvarchar(max)  NOT NULL,
    [Id] bigint  NOT NULL,
    [Person_Id] bigint  NULL
);
GO

-- Creating table 'BaseEntitySet_PersonRoleRelation'
CREATE TABLE [dbo].[BaseEntitySet_PersonRoleRelation] (
    [PersonId] bigint  NULL,
    [PersonTypeId] bigint  NULL,
    [Id] bigint  NOT NULL,
    [PersonType_Id] bigint  NOT NULL
);
GO

-- Creating table 'BaseEntitySet_PersonImage'
CREATE TABLE [dbo].[BaseEntitySet_PersonImage] (
    [ImageData] varbinary(max)  NOT NULL,
    [Id] bigint  NOT NULL,
    [Person_Id] bigint  NULL
);
GO

-- Creating table 'BaseEntitySet_Profession'
CREATE TABLE [dbo].[BaseEntitySet_Profession] (
    [Name] nvarchar(max)  NOT NULL,
    [Id] bigint  NOT NULL,
    [Person_Id] bigint  NULL
);
GO

-- Creating table 'BaseEntitySet_BlogEntryComment'
CREATE TABLE [dbo].[BaseEntitySet_BlogEntryComment] (
    [PersonAttributes_FirstName] nvarchar(max)  NOT NULL,
    [PersonAttributes_LastName] nvarchar(max)  NOT NULL,
    [PersonAttributes_MiddleName] nvarchar(max)  NULL,
    [PersonAttributes_EMail] nvarchar(max)  NOT NULL,
    [Comment] nvarchar(max)  NOT NULL,
    [Id] bigint  NOT NULL,
    [BlogEntry_Id] bigint  NULL
);
GO

-- Creating table 'BaseEntitySet_PersonType'
CREATE TABLE [dbo].[BaseEntitySet_PersonType] (
    [Name] nvarchar(max)  NOT NULL,
    [Id] bigint  NOT NULL
);
GO

-- Creating table 'BaseEntitySet_PhoneType'
CREATE TABLE [dbo].[BaseEntitySet_PhoneType] (
    [Name] nvarchar(max)  NOT NULL,
    [Id] bigint  NOT NULL,
    [Phone_Id] bigint  NULL
);
GO

-- Creating table 'BaseEntitySet_ClubType'
CREATE TABLE [dbo].[BaseEntitySet_ClubType] (
    [Name] nvarchar(max)  NOT NULL,
    [Id] bigint  NOT NULL
);
GO

-- Creating table 'BaseEntitySet_CategoryType'
CREATE TABLE [dbo].[BaseEntitySet_CategoryType] (
    [Name] nvarchar(max)  NOT NULL,
    [Id] bigint  NOT NULL
);
GO

-- Creating table 'BaseEntitySet_CourseType'
CREATE TABLE [dbo].[BaseEntitySet_CourseType] (
    [Name] nvarchar(max)  NOT NULL,
    [Level] nvarchar(max)  NOT NULL,
    [Id] bigint  NOT NULL
);
GO

-- Creating table 'BaseEntitySet_InfrastructureType'
CREATE TABLE [dbo].[BaseEntitySet_InfrastructureType] (
    [Name] nvarchar(max)  NOT NULL,
    [Id] bigint  NOT NULL
);
GO

-- Creating table 'BaseEntitySet_MemberType'
CREATE TABLE [dbo].[BaseEntitySet_MemberType] (
    [Name] nvarchar(max)  NOT NULL,
    [Id] bigint  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'BaseEntitySet'
ALTER TABLE [dbo].[BaseEntitySet]
ADD CONSTRAINT [PK_BaseEntitySet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseEntitySet_Address'
ALTER TABLE [dbo].[BaseEntitySet_Address]
ADD CONSTRAINT [PK_BaseEntitySet_Address]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseEntitySet_City'
ALTER TABLE [dbo].[BaseEntitySet_City]
ADD CONSTRAINT [PK_BaseEntitySet_City]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseEntitySet_Street'
ALTER TABLE [dbo].[BaseEntitySet_Street]
ADD CONSTRAINT [PK_BaseEntitySet_Street]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseEntitySet_Country'
ALTER TABLE [dbo].[BaseEntitySet_Country]
ADD CONSTRAINT [PK_BaseEntitySet_Country]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseEntitySet_Club'
ALTER TABLE [dbo].[BaseEntitySet_Club]
ADD CONSTRAINT [PK_BaseEntitySet_Club]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseEntitySet_Person'
ALTER TABLE [dbo].[BaseEntitySet_Person]
ADD CONSTRAINT [PK_BaseEntitySet_Person]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseEntitySet_Certification'
ALTER TABLE [dbo].[BaseEntitySet_Certification]
ADD CONSTRAINT [PK_BaseEntitySet_Certification]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseEntitySet_Blog'
ALTER TABLE [dbo].[BaseEntitySet_Blog]
ADD CONSTRAINT [PK_BaseEntitySet_Blog]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseEntitySet_BlogEntry'
ALTER TABLE [dbo].[BaseEntitySet_BlogEntry]
ADD CONSTRAINT [PK_BaseEntitySet_BlogEntry]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseEntitySet_Gallery'
ALTER TABLE [dbo].[BaseEntitySet_Gallery]
ADD CONSTRAINT [PK_BaseEntitySet_Gallery]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseEntitySet_Image'
ALTER TABLE [dbo].[BaseEntitySet_Image]
ADD CONSTRAINT [PK_BaseEntitySet_Image]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseEntitySet_Phone'
ALTER TABLE [dbo].[BaseEntitySet_Phone]
ADD CONSTRAINT [PK_BaseEntitySet_Phone]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseEntitySet_InfrastructureObject'
ALTER TABLE [dbo].[BaseEntitySet_InfrastructureObject]
ADD CONSTRAINT [PK_BaseEntitySet_InfrastructureObject]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseEntitySet_Hobby'
ALTER TABLE [dbo].[BaseEntitySet_Hobby]
ADD CONSTRAINT [PK_BaseEntitySet_Hobby]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseEntitySet_AdditionalTrainerData'
ALTER TABLE [dbo].[BaseEntitySet_AdditionalTrainerData]
ADD CONSTRAINT [PK_BaseEntitySet_AdditionalTrainerData]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseEntitySet_Course'
ALTER TABLE [dbo].[BaseEntitySet_Course]
ADD CONSTRAINT [PK_BaseEntitySet_Course]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseEntitySet_CurriculumViateEntry'
ALTER TABLE [dbo].[BaseEntitySet_CurriculumViateEntry]
ADD CONSTRAINT [PK_BaseEntitySet_CurriculumViateEntry]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseEntitySet_PersonRoleRelation'
ALTER TABLE [dbo].[BaseEntitySet_PersonRoleRelation]
ADD CONSTRAINT [PK_BaseEntitySet_PersonRoleRelation]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseEntitySet_PersonImage'
ALTER TABLE [dbo].[BaseEntitySet_PersonImage]
ADD CONSTRAINT [PK_BaseEntitySet_PersonImage]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseEntitySet_Profession'
ALTER TABLE [dbo].[BaseEntitySet_Profession]
ADD CONSTRAINT [PK_BaseEntitySet_Profession]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseEntitySet_BlogEntryComment'
ALTER TABLE [dbo].[BaseEntitySet_BlogEntryComment]
ADD CONSTRAINT [PK_BaseEntitySet_BlogEntryComment]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseEntitySet_PersonType'
ALTER TABLE [dbo].[BaseEntitySet_PersonType]
ADD CONSTRAINT [PK_BaseEntitySet_PersonType]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseEntitySet_PhoneType'
ALTER TABLE [dbo].[BaseEntitySet_PhoneType]
ADD CONSTRAINT [PK_BaseEntitySet_PhoneType]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseEntitySet_ClubType'
ALTER TABLE [dbo].[BaseEntitySet_ClubType]
ADD CONSTRAINT [PK_BaseEntitySet_ClubType]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseEntitySet_CategoryType'
ALTER TABLE [dbo].[BaseEntitySet_CategoryType]
ADD CONSTRAINT [PK_BaseEntitySet_CategoryType]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseEntitySet_CourseType'
ALTER TABLE [dbo].[BaseEntitySet_CourseType]
ADD CONSTRAINT [PK_BaseEntitySet_CourseType]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseEntitySet_InfrastructureType'
ALTER TABLE [dbo].[BaseEntitySet_InfrastructureType]
ADD CONSTRAINT [PK_BaseEntitySet_InfrastructureType]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BaseEntitySet_MemberType'
ALTER TABLE [dbo].[BaseEntitySet_MemberType]
ADD CONSTRAINT [PK_BaseEntitySet_MemberType]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Address_Id] in table 'BaseEntitySet_City'
ALTER TABLE [dbo].[BaseEntitySet_City]
ADD CONSTRAINT [FK_AddressCity]
    FOREIGN KEY ([Address_Id])
    REFERENCES [dbo].[BaseEntitySet_Address]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AddressCity'
CREATE INDEX [IX_FK_AddressCity]
ON [dbo].[BaseEntitySet_City]
    ([Address_Id]);
GO

-- Creating foreign key on [Address_Id] in table 'BaseEntitySet_Street'
ALTER TABLE [dbo].[BaseEntitySet_Street]
ADD CONSTRAINT [FK_AddressStreet]
    FOREIGN KEY ([Address_Id])
    REFERENCES [dbo].[BaseEntitySet_Address]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AddressStreet'
CREATE INDEX [IX_FK_AddressStreet]
ON [dbo].[BaseEntitySet_Street]
    ([Address_Id]);
GO

-- Creating foreign key on [Address_Id] in table 'BaseEntitySet_Country'
ALTER TABLE [dbo].[BaseEntitySet_Country]
ADD CONSTRAINT [FK_AddressCountry]
    FOREIGN KEY ([Address_Id])
    REFERENCES [dbo].[BaseEntitySet_Address]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AddressCountry'
CREATE INDEX [IX_FK_AddressCountry]
ON [dbo].[BaseEntitySet_Country]
    ([Address_Id]);
GO

-- Creating foreign key on [Club_Id] in table 'BaseEntitySet_Address'
ALTER TABLE [dbo].[BaseEntitySet_Address]
ADD CONSTRAINT [FK_ClubAddress]
    FOREIGN KEY ([Club_Id])
    REFERENCES [dbo].[BaseEntitySet_Club]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ClubAddress'
CREATE INDEX [IX_FK_ClubAddress]
ON [dbo].[BaseEntitySet_Address]
    ([Club_Id]);
GO

-- Creating foreign key on [Person_Id] in table 'BaseEntitySet_Address'
ALTER TABLE [dbo].[BaseEntitySet_Address]
ADD CONSTRAINT [FK_PersonAddress]
    FOREIGN KEY ([Person_Id])
    REFERENCES [dbo].[BaseEntitySet_Person]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PersonAddress'
CREATE INDEX [IX_FK_PersonAddress]
ON [dbo].[BaseEntitySet_Address]
    ([Person_Id]);
GO

-- Creating foreign key on [Person_Id] in table 'BaseEntitySet_Certification'
ALTER TABLE [dbo].[BaseEntitySet_Certification]
ADD CONSTRAINT [FK_PersonTest]
    FOREIGN KEY ([Person_Id])
    REFERENCES [dbo].[BaseEntitySet_Person]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PersonTest'
CREATE INDEX [IX_FK_PersonTest]
ON [dbo].[BaseEntitySet_Certification]
    ([Person_Id]);
GO

-- Creating foreign key on [Address_Id] in table 'BaseEntitySet_Certification'
ALTER TABLE [dbo].[BaseEntitySet_Certification]
ADD CONSTRAINT [FK_AddressTest]
    FOREIGN KEY ([Address_Id])
    REFERENCES [dbo].[BaseEntitySet_Address]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AddressTest'
CREATE INDEX [IX_FK_AddressTest]
ON [dbo].[BaseEntitySet_Certification]
    ([Address_Id]);
GO

-- Creating foreign key on [Club_Id] in table 'BaseEntitySet_Blog'
ALTER TABLE [dbo].[BaseEntitySet_Blog]
ADD CONSTRAINT [FK_ClubBlog]
    FOREIGN KEY ([Club_Id])
    REFERENCES [dbo].[BaseEntitySet_Club]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ClubBlog'
CREATE INDEX [IX_FK_ClubBlog]
ON [dbo].[BaseEntitySet_Blog]
    ([Club_Id]);
GO

-- Creating foreign key on [Blog_Id] in table 'BaseEntitySet_BlogEntry'
ALTER TABLE [dbo].[BaseEntitySet_BlogEntry]
ADD CONSTRAINT [FK_BlogBlogEntry]
    FOREIGN KEY ([Blog_Id])
    REFERENCES [dbo].[BaseEntitySet_Blog]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BlogBlogEntry'
CREATE INDEX [IX_FK_BlogBlogEntry]
ON [dbo].[BaseEntitySet_BlogEntry]
    ([Blog_Id]);
GO

-- Creating foreign key on [Gallery_Id] in table 'BaseEntitySet_Image'
ALTER TABLE [dbo].[BaseEntitySet_Image]
ADD CONSTRAINT [FK_GalleryImage]
    FOREIGN KEY ([Gallery_Id])
    REFERENCES [dbo].[BaseEntitySet_Gallery]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_GalleryImage'
CREATE INDEX [IX_FK_GalleryImage]
ON [dbo].[BaseEntitySet_Image]
    ([Gallery_Id]);
GO

-- Creating foreign key on [Person_Id] in table 'BaseEntitySet_Phone'
ALTER TABLE [dbo].[BaseEntitySet_Phone]
ADD CONSTRAINT [FK_PersonPhone]
    FOREIGN KEY ([Person_Id])
    REFERENCES [dbo].[BaseEntitySet_Person]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PersonPhone'
CREATE INDEX [IX_FK_PersonPhone]
ON [dbo].[BaseEntitySet_Phone]
    ([Person_Id]);
GO

-- Creating foreign key on [Club_Id] in table 'BaseEntitySet_InfrastructureObject'
ALTER TABLE [dbo].[BaseEntitySet_InfrastructureObject]
ADD CONSTRAINT [FK_ClubInfrastructureObject]
    FOREIGN KEY ([Club_Id])
    REFERENCES [dbo].[BaseEntitySet_Club]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ClubInfrastructureObject'
CREATE INDEX [IX_FK_ClubInfrastructureObject]
ON [dbo].[BaseEntitySet_InfrastructureObject]
    ([Club_Id]);
GO

-- Creating foreign key on [Address_Id] in table 'BaseEntitySet_InfrastructureObject'
ALTER TABLE [dbo].[BaseEntitySet_InfrastructureObject]
ADD CONSTRAINT [FK_AddressInfrastructureObject]
    FOREIGN KEY ([Address_Id])
    REFERENCES [dbo].[BaseEntitySet_Address]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AddressInfrastructureObject'
CREATE INDEX [IX_FK_AddressInfrastructureObject]
ON [dbo].[BaseEntitySet_InfrastructureObject]
    ([Address_Id]);
GO

-- Creating foreign key on [Person_Id] in table 'BaseEntitySet_Hobby'
ALTER TABLE [dbo].[BaseEntitySet_Hobby]
ADD CONSTRAINT [FK_PersonHobby]
    FOREIGN KEY ([Person_Id])
    REFERENCES [dbo].[BaseEntitySet_Person]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PersonHobby'
CREATE INDEX [IX_FK_PersonHobby]
ON [dbo].[BaseEntitySet_Hobby]
    ([Person_Id]);
GO

-- Creating foreign key on [Person_Id] in table 'BaseEntitySet_AdditionalTrainerData'
ALTER TABLE [dbo].[BaseEntitySet_AdditionalTrainerData]
ADD CONSTRAINT [FK_PersonAdditionalTrainerData]
    FOREIGN KEY ([Person_Id])
    REFERENCES [dbo].[BaseEntitySet_Person]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PersonAdditionalTrainerData'
CREATE INDEX [IX_FK_PersonAdditionalTrainerData]
ON [dbo].[BaseEntitySet_AdditionalTrainerData]
    ([Person_Id]);
GO

-- Creating foreign key on [Club_Id] in table 'BaseEntitySet_Course'
ALTER TABLE [dbo].[BaseEntitySet_Course]
ADD CONSTRAINT [FK_ClubCourse]
    FOREIGN KEY ([Club_Id])
    REFERENCES [dbo].[BaseEntitySet_Club]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ClubCourse'
CREATE INDEX [IX_FK_ClubCourse]
ON [dbo].[BaseEntitySet_Course]
    ([Club_Id]);
GO

-- Creating foreign key on [Course_Id] in table 'BaseEntitySet_Person'
ALTER TABLE [dbo].[BaseEntitySet_Person]
ADD CONSTRAINT [FK_CoursePerson]
    FOREIGN KEY ([Course_Id])
    REFERENCES [dbo].[BaseEntitySet_Course]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CoursePerson'
CREATE INDEX [IX_FK_CoursePerson]
ON [dbo].[BaseEntitySet_Person]
    ([Course_Id]);
GO

-- Creating foreign key on [Person_Id] in table 'BaseEntitySet_CurriculumViateEntry'
ALTER TABLE [dbo].[BaseEntitySet_CurriculumViateEntry]
ADD CONSTRAINT [FK_PersonCurriculumViateEntry]
    FOREIGN KEY ([Person_Id])
    REFERENCES [dbo].[BaseEntitySet_Person]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PersonCurriculumViateEntry'
CREATE INDEX [IX_FK_PersonCurriculumViateEntry]
ON [dbo].[BaseEntitySet_CurriculumViateEntry]
    ([Person_Id]);
GO

-- Creating foreign key on [PersonId] in table 'BaseEntitySet_PersonRoleRelation'
ALTER TABLE [dbo].[BaseEntitySet_PersonRoleRelation]
ADD CONSTRAINT [FK_PersonPersonRoleRelation]
    FOREIGN KEY ([PersonId])
    REFERENCES [dbo].[BaseEntitySet_Person]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PersonPersonRoleRelation'
CREATE INDEX [IX_FK_PersonPersonRoleRelation]
ON [dbo].[BaseEntitySet_PersonRoleRelation]
    ([PersonId]);
GO

-- Creating foreign key on [Person_Id] in table 'BaseEntitySet_PersonImage'
ALTER TABLE [dbo].[BaseEntitySet_PersonImage]
ADD CONSTRAINT [FK_PersonPersonImage]
    FOREIGN KEY ([Person_Id])
    REFERENCES [dbo].[BaseEntitySet_Person]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PersonPersonImage'
CREATE INDEX [IX_FK_PersonPersonImage]
ON [dbo].[BaseEntitySet_PersonImage]
    ([Person_Id]);
GO

-- Creating foreign key on [Person_Id] in table 'BaseEntitySet_Profession'
ALTER TABLE [dbo].[BaseEntitySet_Profession]
ADD CONSTRAINT [FK_PersonProfession]
    FOREIGN KEY ([Person_Id])
    REFERENCES [dbo].[BaseEntitySet_Person]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PersonProfession'
CREATE INDEX [IX_FK_PersonProfession]
ON [dbo].[BaseEntitySet_Profession]
    ([Person_Id]);
GO

-- Creating foreign key on [BlogEntry_Id] in table 'BaseEntitySet_BlogEntryComment'
ALTER TABLE [dbo].[BaseEntitySet_BlogEntryComment]
ADD CONSTRAINT [FK_BlogEntryBlogEntryComment]
    FOREIGN KEY ([BlogEntry_Id])
    REFERENCES [dbo].[BaseEntitySet_BlogEntry]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BlogEntryBlogEntryComment'
CREATE INDEX [IX_FK_BlogEntryBlogEntryComment]
ON [dbo].[BaseEntitySet_BlogEntryComment]
    ([BlogEntry_Id]);
GO

-- Creating foreign key on [PersonType_Id] in table 'BaseEntitySet_PersonRoleRelation'
ALTER TABLE [dbo].[BaseEntitySet_PersonRoleRelation]
ADD CONSTRAINT [FK_PersonTypePersonRoleRelation]
    FOREIGN KEY ([PersonType_Id])
    REFERENCES [dbo].[BaseEntitySet_PersonType]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PersonTypePersonRoleRelation'
CREATE INDEX [IX_FK_PersonTypePersonRoleRelation]
ON [dbo].[BaseEntitySet_PersonRoleRelation]
    ([PersonType_Id]);
GO

-- Creating foreign key on [Phone_Id] in table 'BaseEntitySet_PhoneType'
ALTER TABLE [dbo].[BaseEntitySet_PhoneType]
ADD CONSTRAINT [FK_PhonePhoneType]
    FOREIGN KEY ([Phone_Id])
    REFERENCES [dbo].[BaseEntitySet_Phone]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PhonePhoneType'
CREATE INDEX [IX_FK_PhonePhoneType]
ON [dbo].[BaseEntitySet_PhoneType]
    ([Phone_Id]);
GO

-- Creating foreign key on [Id] in table 'BaseEntitySet_Address'
ALTER TABLE [dbo].[BaseEntitySet_Address]
ADD CONSTRAINT [FK_Address_inherits_BaseEntity]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseEntitySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseEntitySet_City'
ALTER TABLE [dbo].[BaseEntitySet_City]
ADD CONSTRAINT [FK_City_inherits_BaseEntity]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseEntitySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseEntitySet_Street'
ALTER TABLE [dbo].[BaseEntitySet_Street]
ADD CONSTRAINT [FK_Street_inherits_BaseEntity]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseEntitySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseEntitySet_Country'
ALTER TABLE [dbo].[BaseEntitySet_Country]
ADD CONSTRAINT [FK_Country_inherits_BaseEntity]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseEntitySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseEntitySet_Club'
ALTER TABLE [dbo].[BaseEntitySet_Club]
ADD CONSTRAINT [FK_Club_inherits_BaseEntity]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseEntitySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseEntitySet_Person'
ALTER TABLE [dbo].[BaseEntitySet_Person]
ADD CONSTRAINT [FK_Person_inherits_BaseEntity]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseEntitySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseEntitySet_Certification'
ALTER TABLE [dbo].[BaseEntitySet_Certification]
ADD CONSTRAINT [FK_Certification_inherits_BaseEntity]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseEntitySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseEntitySet_Blog'
ALTER TABLE [dbo].[BaseEntitySet_Blog]
ADD CONSTRAINT [FK_Blog_inherits_BaseEntity]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseEntitySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseEntitySet_BlogEntry'
ALTER TABLE [dbo].[BaseEntitySet_BlogEntry]
ADD CONSTRAINT [FK_BlogEntry_inherits_BaseEntity]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseEntitySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseEntitySet_Gallery'
ALTER TABLE [dbo].[BaseEntitySet_Gallery]
ADD CONSTRAINT [FK_Gallery_inherits_BaseEntity]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseEntitySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseEntitySet_Image'
ALTER TABLE [dbo].[BaseEntitySet_Image]
ADD CONSTRAINT [FK_Image_inherits_BaseEntity]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseEntitySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseEntitySet_Phone'
ALTER TABLE [dbo].[BaseEntitySet_Phone]
ADD CONSTRAINT [FK_Phone_inherits_BaseEntity]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseEntitySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseEntitySet_InfrastructureObject'
ALTER TABLE [dbo].[BaseEntitySet_InfrastructureObject]
ADD CONSTRAINT [FK_InfrastructureObject_inherits_BaseEntity]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseEntitySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseEntitySet_Hobby'
ALTER TABLE [dbo].[BaseEntitySet_Hobby]
ADD CONSTRAINT [FK_Hobby_inherits_BaseEntity]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseEntitySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseEntitySet_AdditionalTrainerData'
ALTER TABLE [dbo].[BaseEntitySet_AdditionalTrainerData]
ADD CONSTRAINT [FK_AdditionalTrainerData_inherits_BaseEntity]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseEntitySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseEntitySet_Course'
ALTER TABLE [dbo].[BaseEntitySet_Course]
ADD CONSTRAINT [FK_Course_inherits_BaseEntity]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseEntitySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseEntitySet_CurriculumViateEntry'
ALTER TABLE [dbo].[BaseEntitySet_CurriculumViateEntry]
ADD CONSTRAINT [FK_CurriculumViateEntry_inherits_BaseEntity]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseEntitySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseEntitySet_PersonRoleRelation'
ALTER TABLE [dbo].[BaseEntitySet_PersonRoleRelation]
ADD CONSTRAINT [FK_PersonRoleRelation_inherits_BaseEntity]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseEntitySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseEntitySet_PersonImage'
ALTER TABLE [dbo].[BaseEntitySet_PersonImage]
ADD CONSTRAINT [FK_PersonImage_inherits_BaseEntity]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseEntitySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseEntitySet_Profession'
ALTER TABLE [dbo].[BaseEntitySet_Profession]
ADD CONSTRAINT [FK_Profession_inherits_BaseEntity]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseEntitySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseEntitySet_BlogEntryComment'
ALTER TABLE [dbo].[BaseEntitySet_BlogEntryComment]
ADD CONSTRAINT [FK_BlogEntryComment_inherits_BaseEntity]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseEntitySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseEntitySet_PersonType'
ALTER TABLE [dbo].[BaseEntitySet_PersonType]
ADD CONSTRAINT [FK_PersonType_inherits_BaseEntity]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseEntitySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseEntitySet_PhoneType'
ALTER TABLE [dbo].[BaseEntitySet_PhoneType]
ADD CONSTRAINT [FK_PhoneType_inherits_BaseEntity]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseEntitySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseEntitySet_ClubType'
ALTER TABLE [dbo].[BaseEntitySet_ClubType]
ADD CONSTRAINT [FK_ClubType_inherits_BaseEntity]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseEntitySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseEntitySet_CategoryType'
ALTER TABLE [dbo].[BaseEntitySet_CategoryType]
ADD CONSTRAINT [FK_CategoryType_inherits_BaseEntity]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseEntitySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseEntitySet_CourseType'
ALTER TABLE [dbo].[BaseEntitySet_CourseType]
ADD CONSTRAINT [FK_CourseType_inherits_BaseEntity]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseEntitySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseEntitySet_InfrastructureType'
ALTER TABLE [dbo].[BaseEntitySet_InfrastructureType]
ADD CONSTRAINT [FK_InfrastructureType_inherits_BaseEntity]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseEntitySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'BaseEntitySet_MemberType'
ALTER TABLE [dbo].[BaseEntitySet_MemberType]
ADD CONSTRAINT [FK_MemberType_inherits_BaseEntity]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[BaseEntitySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------